/*
 * com.future CO.,ltd.
 */

package com.future;

import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

/**
 * Description:
 * 重要，
 * 需要知道类MessageDigest、DatatypeConverter在哪个包下
 *
 * @Author: future
 * @Date:2022/3/27:10:21
 */
public class MyHash {

    private static MessageDigest messageDigest;

    static {
        try {
            messageDigest = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public static String generatorHashCode(String str) {
        return DatatypeConverter.printHexBinary(messageDigest.digest(str.getBytes())).toLowerCase();
    }

    public static void main(String[] args) {
        System.out.println("支持的算");
        for (String algorithm : Security.getAlgorithms("MessageDigest")) {
            System.out.println(algorithm);
        }
    }

}
